/*
 * FileName: TextNFontEngine.cs
 * Module: 2D
 * Author: Gourav Das
 * Created: 04/06/2011
 * Modifications: 
 * Copyright: Gourav Das, 2011
 */

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace _22yards._2D
{
    /// <summary>
    /// Inherited from DrawableGameComponent
    /// </summary>
    public class TextNFontEngine:DrawableGameComponent
    {
        #region Members
        /// <summary>
        /// Private Member
        /// </summary>
        private SpriteFont spFont;

        /// <summary>
        /// Private Member
        /// </summary>
        private SpriteBatch spBatch;
        #endregion

        #region Properties
        /// <summary>
        /// Gets or Sets the Text to be drawn onto the screen
        /// </summary>
        public string Text { get; set; }

        /// <summary>
        /// Gets or Sets the Font of the text to be drawn
        /// </summary>
        public string Font { get; set; }

        /// <summary>
        /// Gets or Sets the Color of the Text to be drawn
        /// </summary>
        public Color colour { get; set; }

        /// <summary>
        /// Gets or Sets the Position of the Text to be drawn
        /// </summary>
        public Vector2 Position { get; set; }
        #endregion

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="game" type="Game"></param>
        /// <param name="_font" type="string"></param>
        public TextNFontEngine(Game game, string _font):base(game)
        {
            // Create instances of the sprite font and batch
            spBatch = new SpriteBatch(game.GraphicsDevice);
            Text = string.Empty;
            Font = _font;
            spFont = this.Game.Content.Load<SpriteFont>("TwoDEE/Fonts/" + Font);
            colour = Color.White;
            Position = new Vector2(50.0f, 50.0f);
        }

        /// <summary>
        /// Overridden Draw method, which draws the text onto the screen.
        /// </summary>
        /// <param name="gameTime" type="GameTime"></param>
        public override void Draw(GameTime gameTime)
        {
            spBatch.Begin();
            spBatch.DrawString(spFont, Text, Position, colour);
            spBatch.End();

            base.Draw(gameTime);
        }

        /// <summary>
        /// Overridden Dispose Method. Dispose all non managed components here.
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            spBatch.Dispose();
            base.Dispose(disposing);
        }
    }
}
